<template>
  <el-dialog title="审核驳回"  class="disableBuyer" :visible.sync="isShowModel" @close="$emit('update:isShowDetail', false)" :before-close="handleClose" :close-on-click-modal="false">
    <el-form :model="buyerInfo" :inline="false" label-width="120px" :rules="rules" ref="buyerInfo">
      <el-form-item label="名称：" required>
        {{dataInfo.name}}
      </el-form-item>
      <el-form-item label="审核结果：" required prop="status">
        <el-checkbox v-model="buyerInfo.status" disabled>审核驳回</el-checkbox>
      </el-form-item>
      <el-form-item label="反馈详情：" required prop="content">
        <el-input
          v-model="buyerInfo.content"
          autocomplete="off"
          type="textarea"
          :autosize="{ minRows: 4, maxRows: 6}"
          placeholder="请输入反馈详情（必填）"></el-input>
        <p class="textAreaMsg">{{buyerInfo.content ? buyerInfo.content.length : 0}}/150</p>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="resetModel">取 消</el-button>
      <el-button type="primary" @click="submitStatus" :loading="isSuccess">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  export default {
    name: "SupplierNotPass",
    props: {
      isShowDetail: {
        type: Boolean,
        default: false
      },
      dataInfo: {
        type: Object,
        default: () => {}
      },
      id: {
        type: Number,
        default: 0
      }
    },
    data() {
      return {
        isShowModel: this.isShowDetail,
        buyerInfo: {
          status: true,
          content: ""
        },
        isSuccess: false,
        rules: {
          content: [
            { required: true, message: '请输入反馈详情', trigger: ['blur', 'change'] },
            { max: 150, message: '输入的反馈详情字数不能超过150个字符', trigger: ['blur', 'change'] }
          ]
        }
      }
    },
    methods: {
      submitStatus() {
        let data = {
          ...this.buyerInfo,
          id: this.id,
          statusNum: 1,
          status: 2,
          userId: JSON.parse(window.localStorage.adminLogin).userId
        }
        this.$refs['buyerInfo'].validate((valid) => {
          if (valid) {
            this.isSuccess = true
            ajax.post(apis.user.supplierReview, data).then(res => {
              if(res.code === "10000000") {
                this.$message({
                  type: 'success',
                  message: '驳回成功!'
                });
                // window.localStorage.removeItem('adminLogin')
                // this.$router.push({name: 'login'})
                this.isSuccess = false
                this.resetModel()
                this.$emit('goPrewView')
              } else {
                this.$message.error(res.message)
                this.isSuccess = false
              }
            })
          }
        })
      },
      handleClose(done) {
        this.$refs['buyerInfo'].resetFields()
        this.isShowModel = false
        done()
      },
      resetModel() {
        this.$refs['buyerInfo'].resetFields()
        this.isShowModel = false
      }
    },
    computed: {

    },
    watch: {
      isShowDetail(val) {
        this.isShowModel = val;
      }
    }
  }
</script>

<style lang="scss">
  .disableBuyer {
    .el-dialog {
      width: 500px;
      .textAreaMsg {
        width: 100%;
        text-align: right;
      }
      .tip {
        width: 100%;
        text-align: center;
        font-size: 12px;
        color: #999;
      }
    }
  }
</style>
